package com.hippo.javacore.multithreading;

/**
 * @ClassName ThreadDemo7
 * @Description TODO 常见成员方法--出让线程/礼让线程
 * @Author tangxl
 * @create 2023-03-13 10:43
 **/
public class ThreadDemo7 extends Thread{
    @Override
    public void run() {
        // 循环输出1~100
        for (int i = 1; i < 100 ;i++) {
            System.out.println(getName() + "输出" + i);
            // 表示出让当前CPU的执行权
            Thread.yield();
        }
    }

    public static void main(String[] args) {
        /**
         * public static void yield() 出让线程/礼让线程
         */

        // 创建线程
        Thread t1 = new ThreadDemo7();
        Thread t2 = new ThreadDemo7();

        // 线程命名
        t1.setName("线程1");
        t2.setName("线程2");

        // 线程执行
        t1.start();
        t2.start();
    }
}
